/*
 * @Author: zhangsai
 * @Date: 2018/1/16
 * @Last Modified by: zhangsai
 * @Last Modified time: 2018/1/16
 * @description: 文件列表 混合
 */

import {api} from './api';
import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
import mined from './fileMixin';
export default {
    mixins: [mined],
    data() {
        return {
            // 参数
            params: {
                fileName: '',
                fileType: '',
                businessId: '',
                fileChildType: '',
                industryId: '',
                pageIndex: 1,
                pageSize: 10,
            },
            fileList: {},
            fileChildTypeList: [],
        }
    },
    methods: {
        getDefaultInfo() {
            this.getFileList();
            this.getFileChildType();
        },
        // 获取文件列表
        async getFileList() {
            let params = this.params;
            let resData = await apiHttp(api.GET_FILE_LIST, params);
            if (resData.resCode === STATUS_HTTP_SUCCESS) {
                this.fileList = resData.data || {};
            }
        },
        // 分页
        handleCurrentChange(val) {
            this.params = {...this.params, pageIndex: val};
            this.getFileList();
        },
        // 获取文件夹列表
        async getFileChildType() {
            let params = {
                parentType: this.fileType
            };
            let resData = await apiHttp(api.GET_FILE_CHILD_LIST, params);
            if (resData.resCode === STATUS_HTTP_SUCCESS) {
                this.fileChildTypeList = resData.data || [];
            }
        },
        // 删除文件
        deleteFile(id,index) {
            let params = {
                id: id
            };
            this.$confirm('确认删除此文件?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                let resData = await apiHttp(api.DELETE_FILE, params);
                if (resData.resCode === STATUS_HTTP_SUCCESS) {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.$emit('addDot')
                    if (arguments.length === 1) {
                        this.getFileList();
                        if (this.deleteFileId ) {
                            this.deleteFileId(id)
                        }
                    } else {
                        this.fileShowListArr.splice(index,1) //删除文件 页面显示删除
                        if (this.deleteFileId) {
                            this.deleteFileId(id)
                        }
                    }
                }
            })
        },
    }
}
